<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use App\Logics\Web\Account;
use App\Models\AccountOperate as AccountOperateModel;

class AccountOperate
{
    public function handle(Request $request, Closure $next)
    {
        if ($request->path() != 'web/auth' && $request->path() != 'web/auth/logout') {
            if ($request->getMethod() == 'POST') {
                $model = new AccountOperateModel;
                $model->account_id = Account::id();
                $model->path = $request->path();
                $model->client_ip = $request->getClientIp();
                $model->user_agent = $request->header('user-agent');
                $model->params = json_encode($request->all(), JSON_UNESCAPED_UNICODE);
                $model->operate_time = time();
                $model->save ();
            }
        }
        return $next($request);
    }
}
